package DispatchSys;

import Shared.AmbType;
import Shared.Ambulance;
import Shared.MapPosition;

/**
 * Structure holding the ambulance from the software point of view.
 */

public class AmbulanceInfo extends Ambulance {

	private boolean finished = true;
	private ERInfo emergency = null;
	private boolean confirmed;

	/**
	 * Creates an AmbulanceInfo with ID "id", ambulance type "type" and initial
	 * position "position".
	 * 
	 * @param id
	 *            the IF of the ambulance
	 * @param type
	 *            the type of the ambulance
	 * @param position
	 *            the initial position of the ambulance
	 */
	public AmbulanceInfo(int id, AmbType type, MapPosition position) {
		super(id, type, position);
		register();
	}

	/**
	 * PRE : info != null Assign an ambulance to an Emergency.
	 * 
	 * @param info
	 *            the ERInfo to assign.
	 */

	public void assign(ERInfo info) {
		assert emergency == null;

		super.assign();
		emergency = info;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see Shared.Ambulance#isFree()
	 * 
	 * An ambulance is only free when it's finished status has been
	 * acknowledged...
	 */

	/**
	 * Return whether the ambulance is free (assignment finished and waiting for
	 * a new mission).
	 */
	@Override
	public boolean isFree() {
		return finished && super.isFree();
	}

	/**
	 * 
	 * @return True if the real ambulance has confirmed that it is free.
	 */
	public boolean isFreeConfirmed() {
		return confirmed;
	}

	/**
	 * Set the flag corresponding to the fact that "the real ambulance team has confirmed that is was free".
	 */
	public void confirmFree() {
		confirmed = true;
	}

	/**
	 * Clear the flag corresponding to the fact that "the real ambulance team has confirmed that is was free".
	 */
	public void clearConfirm() {
		confirmed = false;
	}

	/**
	 * Clear the flag corresponding to the fact that "the ambulance has finished his assignment".
	 */
	public void startAssignment() {
		finished = false;
	}

	/**
	 * Set the flag corresponding to the fact that "the ambulance has finished his assignment".
	 * Unassign the ambulance.
	 */
	public void endAssignment() {
		finished = true;
		emergency = null;
	}

}